#!/bin/sh

DAEMON="dusk2dawn"

. /usr/share/common

start() {
	echo_title "Setting $DAEMON"

	if [ ! -x /sbin/$DAEMON ]; then
		echo_error "$DAEMON not found"
		exit 1
	fi

	if grep -q $DAEMON $CRONTABS; then
		echo_info "$DAEMON already in crontab"
	else
		printf "# run $DAEMON nightly at 0:00\n0 0 * * * $DAEMON\n" >> $CRONTABS
		echo_info "$DAEMON added to crontab"
	fi
}

case "$1" in
	start)
		start
		;;
	stop)
		true
		;;
	restart)
		start
		;;
	*)
		echo "Usage: $0 {start|stop|restart}"
		exit 1
		;;
esac

exit 0
